package com.telaxo.shooter2012.gfx {
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.Event;
	/**
	 * @author Jeremy
	 */

	

	public class Smokepuff extends MovieClip
	{
		private var stageRef : Stage;
		private var vitesseLaser : Number =2;
		public var vx:Number;
		public var vy:Number;
		
		[Embed(source ='swf/Smokepuff.swf')]
		private var smokepuff:Class;
		public function Smokepuff(s : Stage, x : Number, y : Number) : void
		{
			stageRef = s;
			vx = 0;
			vy = 0;
			vy =-Math.random() * 3 - 5;
			vx =-Math.random() - Math.random();
			this.x =x;
			this.y = y;
			/*
			if (shipRotation) {
				this.rotation = shipRotation;
				vy -= Math.sin(degreesToRadians(shipRotation - 95)) * vitesseLaser - (Math.random() * 3 - 5);
				vx -= Math.cos(degreesToRadians(shipRotation - 95)) * vitesseLaser -(Math.random() - Math.random());

				this.x = x + vx * 2;
				this.y = y + vy * 2 - 10;
			} else {
				this.x = mouseX;
				this.y = mouseY;
				vy =-Math.random() * 3 - 5;
				vx =-Math.random() - Math.random();
				}
				 *  
				 */
		    var monsmoke:MovieClip = new smokepuff();
			addChild(monsmoke);
			alpha = Math.random();
		//	vx = Math.random() - Math.random();
		//	vy = Math.random() * 3 - 5;
			scaleX = scaleY = Math.random();
			addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
			
		}
		
		private function loop(e:Event) : void
		{
			alpha -= 0.01;
			y -= vy;
			x -= vx;
			scaleX = scaleY += 0.02;
			
		if (x > 520 || y > 420 || x < -20 || y < -20 || alpha <0) removeSelf();
		}
		
		public function degreesToRadians(degrees : Number) : Number {
			return degrees * Math.PI / 180;
		}
		
		private function removeSelf() : void
		{
			removeEventListener(Event.ENTER_FRAME, loop);
			parent.removeChild(this);
		}
		
	}
}
